import { types, Instance } from "mobx-state-tree"
import * as moment from "moment"

export const FightInfoModel = types
  .model("FightInfoModel", {
    homeTeamName: types.string,
    homeTeamIcon: types.string,
    homeTeamScore: types.number,
    awayTeamName: types.string,
    awayTeamIcon: types.string,
    awayTeamScore: types.number,
    startTime: types.Date
  })
  .views(self => ({
    get gameInfo() {
      return self
    },
    get gameBeenTime() {
      return moment(moment().seconds() - moment(self.startTime).seconds()).format("mm:ss")
    }
  }))
  .actions(self => ({
    updateFightInfo(info: any) {
      Object.assign(self, info)
    },
    updateHomeTeamScore(score: number) {
      self.homeTeamScore = score
    },
    updateAwayTeamScore(score: number) {
      self.awayTeamScore = score
    }
  }))

export type FightInfoInstance = Instance<typeof FightInfoModel>
